home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / diskmags / shoah_s_iss1.lha / source / Fractal.s < prev    next >
Encoding:
Text File  |  1991-06-13  |  7.1 KB  |  352 lines

  1. ;      _______  ___                    ___        _______
  2. ;     /°-     \/. /    _____   ____   / ./       /°-     \
  3. ;     \   \___//  \___/°    \_/°   \_/   \___    \   \___/
  4. ;    _/\__    \      ~\_  /\  \  /\ ~\      °\_ _/\__    \
  5. ;    \\       /   /\   /  \/. /  \/   \ //\   / \\       /
  6. ;     \______/\__/  \_/\_____/\____/\_/_/  \_/ o \______/ Issue 1
  7.  
  8. ;Mandlebrot fractal routine
  9. ;I'm not sure who wrote this I'm afraid, someone in Epsilon perhaps ?, well
  10. ;all I've done is make it A1200 compatable and set it up my way...
  11. ;( Also, I don't have a clue how to do fractal routines ! And the lack of
  12. ;comments in this source dosen't really help me much either ! )
  13. ;Squize    17/12/94
  14.  
  15.     opt c-                ;Always set this !
  16.  
  17.     Section    Fractal,Code        ;Always put the code in public mem,
  18.                     ;so people with Fast Ram get the
  19.                     ;benefit
  20.  
  21. ;*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
  22.  
  23.     include    SHOAH.s:SHOAH_Libs/Macros.lib
  24.                     ;I've made some nice macros to
  25.                     ;make life that little bit easier
  26.  
  27. ;*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
  28.  
  29. Start:
  30.     bsr.s    TakeSystem        ;Kill the OS
  31.     tst    d0            ;Did we have an error ?
  32.     bne.s    Error            ;Yes, so quit
  33.  
  34.     bsr    Init            ;Run our little example
  35.  
  36.     bsr    RestoreSystem        ;Finished, so restore the OS
  37.  
  38.     moveq.l    #0,d0            ;Keep Mr.CLI happy
  39. Error:
  40.     rts
  41.  
  42. ;*+*+*+*+*+*+*+*+*+*+*+- Library Routines -+*+*+*+*+*+*+*+*+*+*+*+*+*+*+
  43.     
  44.     include    SHOAH.s:SHOAH_Libs/Startup.lib
  45.  
  46. ;*+*+*+*+*+*+*+*+*+*+*+- Start up Routines -+*+*+*+*+*+*+*+*+*+*+*+*+*+*
  47. Init:
  48.     Copper_Set    Copperlist        ;This is my macro for turning
  49.                         ;on the copperlist
  50.  
  51.     bsr    InstallBmap
  52.  
  53.     move    #%1000001111000000,$96(a5)    ;DMA:Blit/Bitpl/Copper
  54.  
  55.     bsr.s    Main                ;Now run the main loop
  56.  
  57.     rts                    ;All done, so go back to
  58.                         ;"RestoreSystem"
  59.  
  60. ;*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
  61. ;*+*+*+*+*+*+*+*+*+*+*+- The Main Loop -+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
  62. ;*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
  63. MAIN:
  64.  
  65. ;*+*+*+    Plot that nice pattern...
  66.     bsr    Plot_Mandlebrot
  67.  
  68. ;*+*+*+    Check for quit
  69.  
  70.     Mouse_button    Main        ;Another macro, if the left mouse
  71.                     ;button is not pressed then it'll
  72.                     ;loop to main
  73.     rts                ;LMB pressed, so return to "Init"
  74.  
  75. ;*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
  76. ;*+*+*+*+*+*+*+*+*+*+*+- Subroutines -+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
  77. ;*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
  78.  
  79. ;*+*+*+*+*+*+*+*+*+*+*+- Set up the plane pointers -+*+*+*+*+*+*+*+*+*+*
  80. InstallBmap:
  81.     lea    bmapptrs,a0        ;This just sets up 5 bitplanes ( 32
  82.     move.l    #Bmap,d0        ;colours ). It's not the fastest way
  83.     move.w    d0,6(a0)        ;to do this, but because we don't
  84.     swap    d0            ;bother double buffering the screen
  85.     move.w    d0,2(a0)        ;it dosen't really make much
  86.     swap    d0            ;difference
  87.     
  88.     add.l    #8000,d0
  89.     move.w    d0,14(a0)
  90.     swap    d0
  91.     move.w    d0,10(a0)
  92.     swap    d0
  93.     
  94.     add.l    #8000,d0
  95.     move.w    d0,22(a0)
  96.     swap    d0
  97.     move.w    d0,18(a0)
  98.     swap    d0
  99.     
  100.     add.l    #8000,d0
  101.     move.w    d0,30(a0)
  102.     swap    d0
  103.     move.w    d0,26(a0)
  104.     swap    d0
  105.  
  106.     add.l    #8000,d0
  107.     move.w    d0,38(a0)
  108.     swap    d0
  109.     move.w    d0,34(a0)
  110.  
  111.     rts
  112.  
  113. ;*+*+*+*+*+*+*+*+*+*+*+- Do that magic fractal stuff -+*+*+*+*+*+*+*+*+*
  114. Plot_Mandlebrot:
  115.     lea    Bmap,a4
  116.     moveq    #0,d4
  117.     move.l    #-$8000000*2,a1
  118.     move.l    #100,a2
  119.     move.l    #8000,a3
  120.  
  121.     lea    Values,a6            ;Point to the patterns
  122.     move.l    (a6)+,d1            ;Set the x/y values
  123.     move.l    (a6),d2
  124.  
  125.     move.l    #319,d5
  126.     moveq    #$f,d6
  127.     moveq    #7,d7
  128.  
  129. yloop:
  130.     move.l    d5,d3
  131.     move.l    #$8000000*2,a0
  132.     
  133. xloop:
  134.     move.l    a2,d0
  135.  
  136.     movem.l    d1-d7/a2-a6,-(a7)
  137.     move    d0,d3
  138.     moveq    #0,d4            ; q1 = 0
  139.     moveq    #0,d5            ; q2 = 0
  140.     moveq    #0,d6            ; x  = 0
  141.     moveq    #0,d7            ; y  = 0
  142.     subq    #1,d3
  143.  
  144. mandelloop2:
  145.     move.l    d6,d1            ; D1 = oldx;
  146.     move.l    d4,d6
  147.     sub.l    d5,d6
  148.     add.l    a0,d6            ; x(D6) = q1(D4) - q2(D5) + acoo(A0)
  149.     move.l    d1,d2
  150.     bpl.s    Pos1
  151.     neg.l    d1
  152. Pos1:
  153.     eor.l    d7,d2
  154.     tst.l    d7
  155.     bpl.s    Pos2
  156.     neg.l    d7
  157. Pos2:
  158.     move.l    d1,d0
  159.     swap    d0
  160.     move    d0,d2
  161.     mulu    d7,d0
  162.     clr    d0
  163.     swap    d0
  164.     swap    d7
  165.     mulu    d7,d1
  166.     clr    d1
  167.     swap    d1
  168.     mulu    d2,d7
  169.     add.l    d0,d7
  170.     add.l    d1,d7
  171.     tst.l    d2
  172.     bpl.s    Pos3
  173.     neg.l    d7
  174. Pos3:
  175.     moveq    #6,d0
  176.     asl.l    d0,d7
  177.     add.l    a1,d7        ; y(D7) = 2 * oldx(D1) * y(D7) + bcoo(A1)
  178.     moveq    #5,d0
  179.     move.l    d7,d5
  180.     bpl.s    Pos4
  181.     neg.l    d5
  182. Pos4:
  183.     move.l    d5,d2
  184.     swap    d5
  185.     mulu    d5,d2
  186.     clr    d2
  187.     swap    d2
  188.     mulu    d5,d5
  189.     add.l    d2,d5
  190.     add.l    d2,d5
  191.     asl.l    d0,d5            ; q2(D4) = y(D7)^2;
  192.     bvs.s    mandelexit
  193.     move.l    d6,d4
  194.     bpl.s    Pos5
  195.     neg.l    d4
  196. Pos5:
  197.     move.l    d4,d2
  198.     swap    d4
  199.     mulu    d4,d2
  200.     clr    d2
  201.     swap    d2
  202.     mulu    d4,d4
  203.     add.l    d2,d4
  204.     add.l    d2,d4
  205.     asl.l    d0,d4        ; q1(D4) = x(D6)^2;
  206.     bvs.s    mandelexit
  207.     move.l    d4,d0
  208.     add.l    d5,d0
  209.     bvs.s    mandelexit
  210.     cmp.l    #536870912,d0    ;$8000000 * 4
  211.     bgt.s    mandelexit
  212.     dbf    d3,mandelloop2
  213.  
  214.     moveq    #1,d3
  215. mandelexit:
  216.     subq    #1,d3
  217.     move.l    d3,d0
  218.     movem.l    (a7)+,d1-d7/a2-a6
  219.  
  220.     tst    d0
  221.     beq.s    nextx
  222.  
  223.     movem.l    d2-d4/a4,-(sp)    
  224.     move.l    d3,d2
  225.     lsr    #3,d3
  226.     add    d3,d4
  227.     and    d7,d2
  228.     eor.b    d6,d2
  229.     add.l    d4,a4
  230.  
  231.     lsr    d0
  232.     bcc.s    nobp0
  233.     bset    d2,(a4)
  234. nobp0:
  235.     add    a3,a4
  236.     lsr    d0
  237.     bcc.s    nobp1
  238.     bset    d2,(a4)
  239. nobp1:
  240.     add    a3,a4
  241.     lsr    d0
  242.     bcc.s    nobp2
  243.     bset    d2,(a4)
  244. nobp2:
  245.     add    a3,a4
  246.     lsr    d0
  247.     bcc.s    nobp3
  248.     bset    d2,(a4)
  249. nobp3:
  250.     add    a3,a4
  251.     lsr    d0
  252.     bcc.s    nobp4
  253.     bset    d2,(a4)
  254. nobp4:
  255.  
  256. pix_err:    movem.l    (sp)+,d2-d4/a4
  257.  
  258. nextx:
  259.     sub.l    d1,a0
  260.     btst    #6,$bfe001
  261.     beq.s    MouseWait
  262.     dbra    d3,xloop
  263.  
  264. nexty:
  265.     add.l    d2,a1
  266.     add    #40,d4
  267.     cmp    #(200*40),d4
  268.     blt    yloop
  269.  
  270. MouseWait:
  271.     rts
  272.  
  273. ;*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
  274. ;*+*+*+*+*+*+*+*+*+*+*+- Labels -+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+
  275.  
  276. ;Alter these values for your different patterns !
  277. Values    dc.l    $199999            ;X value
  278.     dc.l    $28f5c2            ;Y value
  279.  
  280. ;*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
  281. ;*+*+*+*+*+*+*+*+*+*+*+- Chip-Ram Stuff -+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+
  282.  
  283.     section    ChipRam,Code_c        ;All copperlists/bitplanes/sound/
  284.                     ;sprites/bobs etc. MUST be in
  285.                     ;ChipRam !
  286.  
  287. ;*+*+*+*+*+*+*+*+*+*+*+- Copper Lists -+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+
  288.  
  289. Copperlist:
  290.     dc.w $0100,$5200         ; bit plane control reg.0
  291.     dc.w $0102,$0000         ; scroll value
  292.     dc.w $0104,$0000         ; blp/sprite priority reg.
  293.     dc.w $0108,$0000         ; odd bitplane modulo value
  294.     dc.w $010a,$0000         ; even bitplane modulo value
  295.     dc.w $0180,$0000
  296.     dc.w $0182,$0100
  297.     dc.w $0184,$0200
  298.     dc.w $0186,$0300
  299.     dc.w $0188,$0400
  300.     dc.w $018a,$0500
  301.     dc.w $018c,$0600
  302.     dc.w $018e,$0700
  303.     dc.w $0190,$0800
  304.     dc.w $0192,$0900
  305.     dc.w $0194,$0a00
  306.     dc.w $0196,$0b00
  307.     dc.w $0198,$0c00
  308.     dc.w $019a,$0d00
  309.     dc.w $019c,$0e00
  310.     dc.w $019e,$0f00
  311.     dc.w $01a0,$0fb0
  312.     dc.w $01a2,$0001
  313.     dc.w $01a4,$0002
  314.     dc.w $01a6,$0003
  315.     dc.w $01a8,$0004
  316.     dc.w $01aa,$0005
  317.     dc.w $01ac,$0006
  318.     dc.w $01ae,$0007
  319.     dc.w $01b0,$0008
  320.     dc.w $01b2,$0009
  321.     dc.w $01b4,$000a
  322.     dc.w $01b6,$000b
  323.     dc.w $01b8,$000c
  324.     dc.w $01ba,$000d
  325.     dc.w $01bc,$000e
  326.     dc.w $01be,$000f
  327.  
  328.     dc.w $008e,$2c81         ; upper left corner of disp. window
  329.     dc.w $0090,$f4c1         ; lower right corner of disp. window
  330.     dc.w $0092,$0038         ; start of bpl. (horizontal)
  331.     dc.w $0094,$00d0         ; endo of bpl. (horizontal)
  332. bmapptrs:
  333.     dc.w $00e0,$0000         ; adr of bplane 1 (long - 2 words)
  334.     dc.w $00e2,$0000         ; low word of bplane 1 adr
  335.     dc.w $00e4,$0000
  336.     dc.w $00e6,$0000
  337.     dc.w $00e8,$0000
  338.     dc.w $00ea,$0000
  339.     dc.w $00ec,$0000
  340.     dc.w $00ee,$0000
  341.     dc.w $00f0,$0000
  342.     dc.w $00f2,$0000
  343.  
  344.     dc.l $fffffffe
  345.     dc.l $fffffffe
  346.  
  347. ;*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
  348.     section    BSSBuffers,BSS_c    ;Store screens and null data in a
  349.                     ;BSS section
  350. Bmap:
  351.     dcb.b    8000*5,0
  352.